package com.jic.order.controller.feign;

import com.jic.common.base.vo.RestResult;
import com.jic.order.api.ProductApi;
import com.jic.order.manage.response.OrderResponse;
import com.jic.order.response.HotProductResponse;
import com.jic.order.response.OrderGoodsResponse;
import com.jic.order.service.OrderGoodsService;
import com.jic.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = {"Feign-商品接口"})
@RequestMapping(value = "/feign/product")
@RestController
public class ProductFeign implements ProductApi {

	@Autowired
	private OrderGoodsService orderGoodsService;
	@Autowired
	private OrderService orderService;

	@ApiOperation(value = "根据商品ID查询商品销量")
	@PostMapping("/queryProductSalesByProductID")
	public RestResult<Integer> queryProductSalesByProductId(@RequestBody List<Long> productIds) {
		return orderGoodsService.queryProductSalesByProductId(productIds);
	}

	@ApiOperation(value = "查询TOP8商品和销量")
	@PostMapping("/queryHotProduct")
	public RestResult<List<HotProductResponse>> queryHotProduct() {
		return orderGoodsService.queryHotProduct();
	}

	@RequestMapping(value = "/queryBycommodityCode",method =RequestMethod.GET)
	@ApiOperation(value = "查询商品对应的订单信息")
	@Override
	public List<OrderResponse> queryBycommodityCode(@RequestParam("code")String code, @RequestParam("settStartTime") String settStartTime , @RequestParam("settEndTime") String settEndTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date startTime = sdf.parse(settStartTime);
		Date endTime = sdf.parse(settEndTime);

		return orderService.queryBycommodityCode(code,startTime,endTime);
	}
	@RequestMapping(value = "/queryBycommodityCodeNumber",method =RequestMethod.GET)
	@ApiOperation(value = "查询商品对应的订单数量商品数量信息")
	@Override
	public List<OrderResponse> queryBycommodityCodeNumber(@RequestParam("commodityCode")String commodityCode, @RequestParam("settStartTime") String settStartTime , @RequestParam("settEndTime") String settEndTime) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date startTime = sdf.parse(settStartTime);
		Date endTime = sdf.parse(settEndTime);
		return orderService.queryBycommodityCodeNumber(commodityCode,startTime,endTime);
	}


	@ApiOperation(value = "根据订单编号和商品code查询商品订单明细信息")
	@RequestMapping("/queryByOrderNoAndGoodsCode")
	@Override
	public List<OrderGoodsResponse> queryByOrderNoAndGoodsCode(@RequestParam("commodityCode") String commodityCode, @RequestParam("orderNo") String orderNo) {
		return orderGoodsService.queryByOrderNoAndGoodsCode(commodityCode,orderNo);
	}
}
